package com.hbusa.service.service.impl;

import com.hbusa.dao.impl.ChapterDaoImpl;
import com.hbusa.dao.impl.NovelsDaoImpl;
import com.hbusa.dto.TbChapter;
import com.hbusa.service.ChapterService;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @author Sandwich
 * @version 1.0
 * @date 2021/12/27-0:44
 */
public class ChapterServiceImpl implements ChapterService {

    ChapterDaoImpl chapterDao = new ChapterDaoImpl();

    @Override
    public ArrayList<TbChapter> queryChapterByNovelId(Long id) {
        NovelsDaoImpl novelsDao = new NovelsDaoImpl();
        ArrayList<TbChapter> tbChapters = novelsDao.queryChapterByNovelId(id);
        return tbChapters;
    }

    /**
     * 增加
     * @param chapter 对象
     * @return
     */
    @Override
    public boolean save(TbChapter chapter) {
        return chapterDao.save(chapter);
    }

    /**
     * 通过id删除
     * @param chapterId 要删除的章节id
     * @return
     */
    @Override
    public boolean removeById(int chapterId) {
        return chapterDao.removeById(chapterId);
    }

    /**
     * 修改
     * @param chapter 修改之后的对象
     * @return
     */
    @Override
    public boolean modify(TbChapter chapter){
        boolean modify = false;
        try {
            modify = chapterDao.modify(chapter);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return modify;
    }

    /**
     * 查找所有的章节
     * @return 返回一个ArrayList
     */
    @Override
    public ArrayList<TbChapter> findAllChapter() {
        return chapterDao.findAllChapter();
    }

    /**
     * 通过章节数查找小说
     * @param chapterId 章节id
     * @return 返回的是这个小说对象
     */
    @Override
    public TbChapter findChapterById(int chapterId) {
        return chapterDao.findChapterByNum(chapterId);
    }
}
